<?php defined('_JEXEC') or die('Restricted access'); ?>

<form action="index.php" method="post" name="adminForm" id="adminForm">
<div class="col width-50">
	<fieldset class="adminform">
		<legend><?php echo JText::_( 'Details' ); ?></legend>

		<table class="admintable">
		<tr>
			<td width="100" align="right" class="key">
				<label for="greeting">
					<?php echo JText::_( 'Site Name' ); ?>:
				</label>
			</td>
			<td>
				<input class="text_area" type="text" name="name" id="name" size="32" maxlength="250" value="<?php echo $this->multisite->name;?>" />
			</td>
		</tr>
		<tr>
			<td width="100" align="right" class="key">
				<label for="url">
					<?php echo JText::_( 'Site URL' ); ?>:
				</label>
			</td>
			<td>
				<?php echo $this->multisite->url;?>
				<input class="text_area" type="hidden" name="url" id="url" size="40" maxlength="250" value="<?php echo $this->multisite->url;?>" />
			</td>
		</tr>
		<tr>
			<td width="100" align="right" class="key">
				<label for="prefix">
					<?php echo JText::_( 'Database Prefix' ); ?>:
				</label>
			</td>
			<td>
				<?php echo $this->multisite->prefix;?>
				<input class="text_area" type="hidden" name="prefix" id="prefix" size="15" maxlength="15" value="<?php echo $this->multisite->prefix;?>" />
			</td>
		</tr>
		
	</table>
	</fieldset>
</div>
<div class="col width-50">
	<fieldset>
		<legend><?php echo JText::_('Table Options'); ?></legend>
		<table>
		<?php foreach ($this->tables as $table){
				$nopretable=preg_replace('/'.$this->multisite->prefix.'/', '', $table);
				$isview=0;
				echo "<tr>";
				echo "<td width=100 align=right class=key>";
				echo "<label for=prefix>";
				echo JText::_($table);
				echo "</label>";
				echo "</td>";
				echo "<td>";
				echo "<select name=".$table.">";
				foreach ($this->views as $view){
					if ($view==$table){
						$isview=1;
					}
				}
				if ($isview==1){
					$sites=$this->sites;
					$viewdefs=$this->viewdefs;
					$selected;
					foreach ($viewdefs as $viewdef){
						if ($viewdef->TABLE_NAME==$table){
							foreach ($sites as $site){
								if ($site->prefix != $this->multisite->prefix){
									$temp_table=preg_replace('/'.$this->multisite->prefix.'/', '', $table);
									if(preg_match('/'.$site->prefix.$temp_table.'/', $viewdef->VIEW_DEFINITION)){
										$selected=$site->id;
									}
								}
							}
						}
					}
					echo '<option value=seperate>Standalone</option>';
					foreach ($sites as $site){
						if ($site->prefix!=$this->multisite->prefix){
							if ($selected==$site->id){
								echo '<option value='.$site->id.' selected>Points to '.$site->name.'</option>';
							} else{
								echo '<option value='.$site->id.'>Points to '.$site->name.'</option>';
							}
						}
					}
				} else {
					echo '<option value=seperate selected>Standalone</option>';
					foreach ($sites as $site){
						if ($site->prefix!=$this->multisite->prefix){
							echo '<option value='.$site->id.'>Points to '.$site->name.'</option>';
						}
					}	
				}
				echo '</select>';
				echo '</td>';
				echo '<td>';
				// Access Controls
				if ($nopretable=='access_action_rule_map' || $nopretable=='access_actions' || $nopretable=='access_asset_assetgroup_map'  
				|| $nopretable=='access_asset_rule_map' || $nopretable=='access_assetgroup_rule_map' || $nopretable=='access_assetgroups'
				|| $nopretable=='access_assets' || $nopretable=='access_rules' || $nopretable=='access_sections'){
					echo ' &nbsp;&nbsp;<i>(Access Controls)</i>';
				}
				// Banner Component
				else if ($nopretable=='banner' || $nopretable=='bannerclient' || $nopretable=='bannertrack'){
					echo ' &nbsp;&nbsp;<i>(Banner Component)</i>';
				}
				// Content
				else if ($nopretable=='categories' || $nopretable=='content' || $nopretable=='content_rating' || $nopretable=='content_frontpage'){
					echo ' &nbsp;&nbsp;<i>(Content)</i>';
				}
				// Contacts Component
				else if ($nopretable=='contact_details'){
					echo ' &nbsp;&nbsp;<i>(Contact Component)</i>';
				}
				// Extensions + Components
				else if ($nopretable=='extensions' || $nopretable=='components'){
					echo ' &nbsp;&nbsp;<i>(Extensions/Components)</i>';
				}
				// Core
				else if ($nopretable=='core_log_items' || $nopretable=='core_log_searches' || $nopretable=='schemas'
					|| $nopretable=='stats_agents'){
					echo ' &nbsp;&nbsp;<i>(Core)</i>';
				}
				// Menus
				else if ($nopretable=='menu' || $nopretable=='menu_template' || $nopretable=='menu_types'){
					echo ' &nbsp;&nbsp;<i>(Menus)</i>';
				}
				// Messages
				else if ($nopretable=='messages' || $nopretable=='messages_cfg'){
					echo ' &nbsp;&nbsp;<i>(Messages)</i>';
				}
				// Modules
				else if ($nopretable=='modules' || $nopretable=='modules_menu'){
					echo ' &nbsp;&nbsp;<i>(Modules)</i>';
				}
				// Multisite Component
				else if ($nopretable=='multisite'){
					echo ' &nbsp;&nbsp;<i>(Multisite Component)</i>';
				}
				// Newsfeeds Component
				else if ($nopretable=='newsfeeds'){
					echo ' &nbsp;&nbsp;<i>(Newsfeeds Component)</i>';
				}
				// Redirect Component
				else if ($nopretable=='redirect_links'){
					echo ' &nbsp;&nbsp;<i>(Redirect Component)</i>';
				}
				// Updates
				else if ($nopretable=='update_categories' || $nopretable=='update_sites' || $nopretable=='update_sites_extensions'
					|| $nopretable=='updates'){
					echo ' &nbsp;&nbsp;<i>(Updates)</i>';
				}
				// Users
				else if ($nopretable=='user_rule_map' || $nopretable=='user_usergroup_map' || $nopretable=='usergroup_rule_map'
					|| $nopretable=='usergroups' || $nopretable=='users' || $nopretable=='session'){
					echo ' &nbsp;&nbsp;<i>(Users)</i>';
				}
				// Weblinks Component
				else if ($nopretable=='weblinks'){
					echo ' &nbsp;&nbsp;<i>(Weblinks Component)</i>';
				}
				else {
					echo ' &nbsp;&nbsp;<i>(Other)</i>';			
				}
				echo '</td>';
				echo '</tr>';
			} ?>
		</table>

	</fieldset>
</div>

<div class="clr"></div>

<input type="hidden" name="option" value="com_multisite" />
<input type="hidden" name="id" value="<?php echo $this->multisite->id; ?>" />
<input type="hidden" name="task" value="" />
<input type="hidden" name="controller" value="multisite" />
</form>